<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>分析生命周期</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <div id="root">
            <h2>n值:{{n}}</h2>
            <button @click="add">点击</button>
            <button @click="bye">删除vm实例</button>
        </div>
        <script type="text/javascript">
            Vue.config.productionTip = false    // 阻止Vue在启动时生成生产提示

            // 创建Vue实例，开端
            const vm = new Vue({
                el: '#root', // el用于指定当前Vue实例为哪个容器服务，值通常为css选择器字符串。
                data: {     // data中用于存储数据，数据供el指定的容器去使用
                    n: 1
                },
                methods: {
                    add: function(){
                        this.n++
                    },
                    bye: function(){
                        console.log('bye')
                        this.$destroy()
                    }
                },
                beforeCreate() {
                    console.log('beforeCreate')
                    // 运行到debugger这里不再往下执行了
                    // debugger;
                },
                created() {
                    console.log("created")
                },
                beforeMount() {
                    console.log("beforeMount")
                },
                mounted() {
                    console.log('mounted')
                },
                beforeUpdate() {
                    console.log('beforeUpdate')
                },
                updated() {
                    console.log('updated')
                },
                beforeDestroy() {
                    console.log('beforeDestroy')
                },
                destroyed() {
                    console.log('destroyed')
                },
            })
        </script>
    </body>
</html>
